package com.wmlive.hhvideo.heihei.personal.adapter;

import android.view.View;
import android.view.ViewGroup;

import cn.wmlive.hhvideo.R;

import com.wmlive.hhvideo.heihei.beans.personal.ListFollowerFansEntry;
import com.wmlive.hhvideo.heihei.beans.personal.UserHomeRelation;
import com.wmlive.hhvideo.utils.imageloader.GlideLoader;
import com.wmlive.hhvideo.widget.refreshrecycler.RefreshAdapter;
import com.wmlive.hhvideo.widget.refreshrecycler.RefreshRecyclerView;

import java.util.List;

/**
 * Created by XueFei on 2017/5/27.
 */

public class FocusAdapter extends RefreshAdapter<FocusHolder, ListFollowerFansEntry> {
    private long mCurrentId = 0;

    public FocusAdapter(RefreshRecyclerView refreshView, List<ListFollowerFansEntry> list, long current_id) {
        super(list, refreshView);
        mCurrentId = current_id;
    }

    @Override
    public FocusHolder onCreateHolder(ViewGroup parent, int viewType) {
        return new FocusHolder(parent, R.layout.activity_focus_item);
    }

    @Override
    public void onBindHolder(FocusHolder holder, final int position, ListFollowerFansEntry data) {
        GlideLoader.loadCircleImage(data.getCover_url(), holder.ivFocusItemHead, R.drawable.icon_profile_bg_user_default);
        holder.tvFocusItemName.setText(data.getName());
        UserHomeRelation relation = data.getRelation();
        if (mCurrentId == data.getId()) {
            holder.ivFocusItemState.setVisibility(View.GONE);
        } else {
            if (null != relation) {
                if (relation.is_follow() && relation.is_fans()) {
                    GlideLoader.loadImage(R.drawable.icon_friend_followeach, holder.ivFocusItemState, R.drawable.icon_profile_other_add);
                } else if (relation.is_follow()) {
                    GlideLoader.loadImage(R.drawable.icon_friend_check_nor, holder.ivFocusItemState, R.drawable.icon_profile_other_add);
                } else if (relation.is_fans()) {
                    GlideLoader.loadImage(R.drawable.icon_profile_other_add, holder.ivFocusItemState, R.drawable.icon_profile_other_add);
                } else {
                    GlideLoader.loadImage(R.drawable.icon_profile_other_add, holder.ivFocusItemState, R.drawable.icon_profile_other_add);
                }
            } else {
                GlideLoader.loadImage(R.drawable.icon_profile_other_add, holder.ivFocusItemState, R.drawable.icon_profile_other_add);
            }
        }
        holder.ivFocusItemState.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mOnClickFocusCustom) {
                    mOnClickFocusCustom.onClick(v, position);
                }
            }
        });
    }

    private OnClickFocusCustom mOnClickFocusCustom;

    public interface OnClickFocusCustom {
        void onClick(View view, int position);
    }

    public void setOnClickCustom(OnClickFocusCustom onClickFocusCustom) {
        mOnClickFocusCustom = onClickFocusCustom;
    }
}
